package com.gin.supermarket_inventory_system.inventory.dto.param;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gin.database.dto.param.BasePageParam;
import com.gin.database.validation.EntityId;
import com.gin.supermarket_inventory_system.inventory.enums.InventoryReceiptType;
import com.gin.supermarket_inventory_system.inventory.service.PurveyorService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

/**
 * 库存单据分页查询参数
 * @since : 2023/10/12 14:48
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@Schema(description = "分页查询参数: 库存单据")
public class InventoryReceiptPageParam extends BasePageParam {
    @Parameter(description = "单据类型")
    InventoryReceiptType type;

    @Parameter(description = "供应商ID")
    @EntityId(service = PurveyorService.class, nullable = true)
    Long purveyorId;

    @Parameter(description = "创建时间（起）")
    Long start;

    @Parameter(description = "创建时间（止）")
    Long end;

    @Override
    public void handleQueryWrapper(QueryWrapper<?> queryWrapper) {
        if (type != null) {
            queryWrapper.eq("type", type.name());
        }
        if (purveyorId != null) {
            queryWrapper.eq("purveyor_id", purveyorId);
        }
        if (start != null) {
            queryWrapper.ge("time_create", start);
        }
        if (end != null) {
            queryWrapper.le("time_create", end);
        }

    }
}
